<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改APP版本管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-version-edit" th:object="${fseStAppVersion}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">版本名称：</label>
                <div class="col-sm-8">
                    <input name="versionName" th:field="*{versionName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">版本号：</label>
                <div class="col-sm-8">
                    <input id="versionCode"  name="versionCode" th:field="*{versionCode}" class="form-control" type="text" onchange="changeVersionCode()" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">版本描述：</label>
                <div class="col-sm-8">
                    <input  name="versionDesc" th:field="*{versionDesc}"  class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required" >服务条款：</label>
                <div class="col-sm-8">
                    <input  id="termsOfService" name="termsOfService" th:field="*{termsOfService}" type="hidden" required>
                    <div id="editorTermsOfService" class="summernoteTermsOfService"></div>
                </div>
            </div>
           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">服务条款：</label>
                <div class="col-sm-8">
                    <textarea name="termsOfService" class="form-control">[[*{termsOfService}]]</textarea>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">发布状态：</label>
                <div class="col-sm-8">
                    <label class="check-box" >
                        <input name="releaseState" th:checked="*{releaseState=='0'}" class="form-control" type="radio"  value="0" required>未发布
                    </label>
                    <label class="check-box" >
                        <input name="releaseState" th:checked="*{releaseState=='1'}" class="form-control" type="radio"  value="1" required>已发布
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">发布时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input name="releaseDate" th:value="${#dates.format(fseStAppVersion.releaseDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">app下载地址：</label>
                <div class="col-sm-8">
                    <input name="appUrl" th:field="*{appUrl}" class="form-control" type="text" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        /*富文本框*/
        $(function() {
            $('.summernoteTermsOfService').summernote({
                placeholder: '请合理输入内容',
                height : 192,
                lang : 'zh-CN',
                followingToolbar: false,
                callbacks: {
                    onImageUpload: function (files) {
                        sendFile(files[0], this);
                    }
                },
                toolbar: [
                    ['style', ['style']],
                    ['font', ['bold', 'underline', 'clear']],
                    ['color', ['color']],
                    ['para', ['ul', 'ol', 'paragraph']],
                ]
            });
            var content = $("#termsOfService").val();
            $('#editorTermsOfService').summernote('code', content);
            var termsOfService = $('.summernoteTermsOfService').summernote('code');
            $("#termsOfService").val(termsOfService);
        });
        var prefix = ctx + "fsepc/version";
        $("#form-version-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {

                if ($.validate.form()) {
                    /*  将富文本内容赋值给id为termsOfService的隐藏域*/
                    var termsOfService= $('.summernoteTermsOfService').summernote('code');
                    $("#termsOfService").val(termsOfService);
                    /* 提交前验证是否填写服务条款*/
                    if($("#termsOfService").val()==null||$("#termsOfService").val()==''||$("#termsOfService").val()=="<p><br></p>"){
                        alert("您还没有填写服务条款");
                    }else{
                        $.operate.save(prefix + "/edit", $('#form-version-edit').serialize());
                    }

                }


        }

        $("input[name='releaseDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /* 修改时判断版本号格式是否正确*/
        function changeVersionCode() {
            var versionCode= $("#versionCode").val();
            if(isNaN(versionCode)&&versionCode!=null&&versionCode!=''){
                alert("版本号格式不正确");
                $("#versionCode").val("");

            }else{
                /*验证版本号是否重复*/
                if(versionCode!=null&&versionCode!=''){
                    $.post(ctx+"fsepc/version/selectByVersionCode",{versionCode:document.getElementById("versionCode").value},function (data) {
                        if(data.length!=0){
                            if(data[0].versionCode!=[[${fseStAppVersion.versionCode}]]){
                                alert("版本号已存在")
                                $("#versionCode").val("");
                            }
                        }
                    },"json")
                }

            }
        }
    </script>
</body>
</html>